package second.graph;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class Solution12 {
    public boolean canVisitAllRooms(List<List<Integer>> rooms) {
        boolean[] visited = new boolean[rooms.size()];
        dfs(rooms, visited, 0);
        for (boolean f : visited) {
            if (!f) return false;
        }
        return true;
    }

    public void dfs(List<List<Integer>> rooms, boolean[] visites, int key) {
        visites[key] = true;
        List<Integer> list = rooms.get(key);
        for (int x : list) {
            if (!visites[x]) dfs(rooms, visites, x);
        }
    }
}

